#define DEBUG
#include <cstdio>
#define MAXN 1500
#define MAXM 1500

using namespace std;

void sort(int *a, int l, int r) {
  int i=l, j=r, mid=a[(l+r)/2], temp;
  for (; i<=j; ) {
    for (; a[j]>mid; j--);
    for (; a[i]<mid; i++);
    if (i<=j) {
      temp=a[i], a[i]=a[j], a[j]=temp;
      i++, j--;
    } 
  }
  if (i<r) {
    sort(a, i, r);
  }
  if (j>l) {
    sort(a, l, j);
  }
}

int main() {
#ifdef DEBUG
  freopen("2.in", "r", stdin);
  freopen("2.out", "w", stdout);
#endif
  
  static int first[MAXN+1], a[2][MAXM+1], book[MAXM+1];
  int k, m, n;
  scanf("%d %d %d", &k, &m, &n);
  for (int i=1; i<=n; i++) {
    scanf("%d", first+i);
    a[1][i] = first[i];
  }
  a[1][0] = n;

  for (int i=2; i<=k; i++) {
    a[i%2][0] = 0;
    for (int j=1; j<=n; j++) {
      for (int k=1; k<=a[(i-1)%2][0]; k++) {
	if (book[first[j]*a[(i-1)%2][k]%m]!=i) {
	  a[i%2][++a[i%2][0]] = first[j]*a[(i-1)%2][k]%m;
	  book[a[i%2][a[i%2][0]]]=i;
	}
      }
    }
  }

  sort(a[k%2], 1, a[k%2][0]);
  for (int i=1; i<=a[k%2][0]; i++) {
    printf("%d ", a[k%2][i]);
  }

  fcloseall();
  return 0;
}
